#include "Date.h"
#include <iostream>
#include<string>
#include <iomanip>
#include <sstream>

using namespace std;

Date::Date(void)
{
	time_t seconds = time (NULL);
   struct tm * timeinfo = localtime (&seconds);
   ostringstream oss;
   oss << (timeinfo->tm_year + 1900) << "-" << std::setw(2) << std::setfill('0') << (timeinfo->tm_mon + 1) << "-" << std::setw(2) << std::setfill('0') << timeinfo->tm_mday; 
   date = oss.str();
   char y[4]; char m[2]; char d[2];
   m[0]=date[5];m[1]=date[6];
   d[0]=date[8];d[1]=date[9];
   for(int i =0;i<4;i++){y[i]=date[i];}
   
   day = atoi(d);
   month = atoi(m);
   year = atoi(y);

}
Date::Date(int d, int m, int y)
{
	day = d ; month = m ; year = y;
}

int Date::getday()
{
	return day;
}

int Date::getmonth()
{
	return month;
}

int Date::getyear()
{
	return year;
}

void Date::setday(int x)
{
	day = x;
}

void Date::setmonth(int x)
{
	month = x;
}

void Date::setyear(int x)
{
	year = x;
}

string Date::show_date()
{
	return date;
}

 void Date::return_date()
{
	switch (month)
	{
	case 2: // 28 or 29 days
		{
			if (day < 19)
			{ day = day+10;}
			else 
			{
				month = month +1;
				day =day + 10 -28;
			}
		}
		break;

	case 1 : case 3 : case 5 : case 7 : case 8 : case 10 :  // 31 days
		{
			if(day <22)
			{ day = day +10;}
			else 
			{
				month = month +1;
				day = day + 10 -31;
			}
		}
		break;
	case 4 : case 6 : case 9 : case 11: // 30 days
		{
			if (day <21)
			{ day = day +10;}
			else 
			{
				month = month +1;
				day = day +10 -30;
			}
		}
		break;
	case 12:
		{
			if(day < 22)
			{ day = day +10;}
			else 
			{
				year = year + 1;
				month = 1;
				day = day + 10 -31;
			}
		}
		break;
	}
}

bool Date::checkless()
{

	Date today;

	if((year >= today.getyear()) && (month >= today.getmonth()) && (day >=today.getday()))
	{
		return true;
	}
	else { return false ;}
	
}

bool Date::checkequal()
{
	Date today;
	if((year == today.getyear()) && (month == today.getmonth()) && (day == today.getday()))
	{
		return true;
	}
	else { return false ;}
	
}